package com.webas.mixins;

import org.apache.tapestry5.model.MutableComponentModel;
import org.apache.tapestry5.services.ClassTransformation;
import org.apache.tapestry5.services.ComponentClassResolver;
import org.apache.tapestry5.services.ComponentClassTransformWorker;

public class ShowComponentWorker implements ComponentClassTransformWorker
{
    private final ComponentClassResolver resolver;

    public ShowComponentWorker( final ComponentClassResolver resolver ) {
            this.resolver = resolver;
    }

    public void transform( ClassTransformation transformation, MutableComponentModel model)
    {
            String componentClassName = model.getComponentClassName();

            // Place your general rules to filter components here. Place often changing rules to the mixin - thus you can enjoy the live reloading
            if ( componentClassName.startsWith( "com.webas.components." ) ) {
                    if ( model.getMeta( "transformed" ) != null )
                            return;
                    model.setMeta( "transformed", "transformed" );

                    String mixinClassName = resolver.resolveMixinTypeToClassName( "ShowComponentName" );

                    model.addMixinClassName( mixinClassName );
            }

    }
}